﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using Com.Web.coffinegurunaru.AppLogic.Page;
using Com.Web.coffinegurunaru.AppLogic;
using Com.Framework;
using Com.Framework.Data;
using Com.Library.DB.Store;
using Com.Library.Page;

namespace Com.Web.coffinegurunaru.manager.store
{
	public partial class storemethod : ManagerAjaxPage
	{
		public string[] GetNewStore(int PageNo, byte PageSize)
		{
			ListData<NewStoreEntity, OutputEntity> result = StoreModel.GetListByNewStore(PageNo, PageSize);
			string[] retValue = new string[3];
			Dictionary<string, object> properties = new Dictionary<string, object>();
			properties.Add("NewStoreList", result.Record);
			properties.Add("PageNo", PageNo);
			retValue[0] = ViewManager<ManagerPage>.Render("/manager/store/newstorelist.ascx", properties);
			retValue[1] = result.Output.CntTotal.ToString();

			return retValue;
		}

		public void CreateImage(int StoreNo, string ImageURLs)
		{
			string[] arrImage = ImageURLs.Split(',');
			StoreModel.ImageRemove(StoreNo, null);
			foreach (string item in arrImage)
			{
				StoreModel.ImageCreate(StoreNo, item, this.WebCookies.ManagerName);
			}
		}

		public string GetNaverAddr(string Address)
		{
			string XMLData = NaverAPI.GetGEOCode(Address);
			List<NaverAPIPointInfo> list = NaverAPI.ParseGEOCode(XMLData);

			string retValue = string.Empty;
			Dictionary<string, object> properties = new Dictionary<string, object>();
			properties.Add("MapPoints", list);
			retValue = ViewManager<ManagerPage>.Render("/manager/store/naveraddresslist.ascx", properties);

			return retValue;
		}

		public void SetStoreActive(string UserID, string IsActive)
		{
			StoreModel.SetActive(UserID, IsActive, this.WebCookies.ManagerName);
		}

		public int CreateStore(string UserID, string IsActive, string StoreName, string CompanyNo, string Phone, string PostNo, string Address, string CityName
			, string IsTakeout, string Takeout, string IsParking, string Parking
			, string StoreSize, string OpenDate, string OpenTime, string PointX, string PointY, string Description)
		{
			int StoreNo = StoreModel.Create(UserID, IsActive, StoreName, CompanyNo, Phone, PostNo, Address, CityName, IsTakeout, Takeout, IsParking, Parking, StoreSize, OpenDate, OpenTime, PointX, PointY, Description, this.WebCookies.ManagerName);

			return StoreNo;
		}

		public void ModifyStore(int StoreNo, string IsActive, string StoreName, string CompanyNo, string Phone, string PostNo, string Address, string CityName, string IsParking, string Parking
			, string IsTakeout, string Takeout
			, string StoreSize, string OpenDate, string OpenTime, string PointX, string PointY, string Description)
		{
			StoreModel.Modify(StoreNo, IsActive, StoreName, CompanyNo, Phone, PostNo, Address, CityName, IsTakeout, Takeout, IsParking, Parking, StoreSize, OpenDate, OpenTime, PointX, PointY, Description, this.WebCookies.ManagerName);
		}

		public string[] GetStoreList(string IsActive, string CityName, string StoreName, int PageNo, byte PageSize)
		{
			ListData<StoreEntity, OutputEntity> result = null;
			if (CityName == string.Empty && StoreName == string.Empty)
			{
				result = StoreModel.GetList(IsActive, PageNo, PageSize);
			}
			else
			{
				result = StoreModel.GetSearch(CityName, StoreName, PageNo, PageSize);
			}
			string[] retValue = new string[3];
			Dictionary<string, object> properties = new Dictionary<string, object>();
			properties.Add("StoreList", result.Record);
			properties.Add("IsActive", IsActive);
			retValue[0] = ViewManager<ManagerPage>.Render("/manager/store/storelst.ascx", properties);
			retValue[1] = result.Output.CntTotal.ToString();
			return retValue;
		}

		public string[] GetStoreSimpleList(string IsActive, int PageNo, byte PageSize)
		{
			ListData<StoreEntity, OutputEntity> result = StoreModel.GetList(IsActive, PageNo, PageSize);
			string[] retValue = new string[3];
			Dictionary<string, object> properties = new Dictionary<string, object>();
			properties.Add("StoreList", result.Record);
			properties.Add("PageNo", PageNo);
			retValue[0] = ViewManager<ManagerPage>.Render("/manager/store/beststorelist.ascx", properties);
			retValue[1] = result.Output.CntTotal.ToString();
			return retValue;
		}

		public string GetOpenStoreList(int PageNo, byte PageSize)
		{
			string retValue = string.Empty;
			ListData<StoreBestEntity, OutputEntity> result = StoreModel.BestGetList(PageNo, PageSize);
			Dictionary<string, object> properties = new Dictionary<string, object>();
			properties.Add("BestList", result.Record);
			retValue = ViewManager<ManagerPage>.Render("/manager/store/openstorelist.ascx", properties);

			return retValue;
		}

		public string GetOpenStoreInfo(int StoreNo)
		{
			StoreEntity info = StoreModel.GetInfo(StoreNo);
			string retValue = string.Empty;

			Dictionary<string, object> properties = new Dictionary<string, object>();
			properties.Add("StoreInfo", info);
			retValue = ViewManager<ManagerPage>.Render("/manager/store/newstoreinfo.ascx", properties);
			return retValue;
		}

		public string GetStoreInfo(int StoreNo)
		{
			StoreEntity info = StoreModel.GetInfo(StoreNo);

			string retValue = string.Empty;
			Dictionary<string, object> properties = new Dictionary<string, object>();
			properties.Add("StoreInfo", info);
			retValue = ViewManager<ManagerPage>.Render("/manager/store/storeinfo.ascx", properties);
			return retValue;
		}

		public void AddBestStore(int StoreNo)
		{
			StoreModel.BestCreate(StoreNo, this.WebCookies.ManagerName);
		}

		public void RemoveBestStore(int StoreNo)
		{
			StoreModel.BestRemove(StoreNo);
		}
	}
}
